package com.pg.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pg.common.ReturnResult;
import com.pg.entity.GkGd;
import com.pg.service.GkGdService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhanghongbin
 * @since 2020-04-13
 */
@RestController
@RequestMapping("/gkGd")
public class GkGdController {

    @Autowired
    private GkGdService gkGdService;

    @AutoLog(value = "添加 工频耐受电压")
    @RequestMapping("/add")
    public ReturnResult add(@RequestBody GkGd gkGd) {
        gkGd.setManufactureOrderRef(UUID.randomUUID().toString());
        gkGdService.save(gkGd);
        ReturnResult returnResult = new ReturnResult();
        returnResult.setErrorCode("0");
        returnResult.setData("添加成功");
        return returnResult;
    }

    @RequestMapping("/delete")
    public ReturnResult delete(@RequestBody GkGd zpgEipDlqHgjwd) {
        gkGdService.updateById(zpgEipDlqHgjwd);
        ReturnResult returnResult = new ReturnResult();
        returnResult.setErrorCode("0");
        returnResult.setData("删除成功");
        return returnResult;
    }

    @RequestMapping("/edit")
    public ReturnResult edit(@RequestBody GkGd zpgEipDlqHgjwd) {
        gkGdService.updateById(zpgEipDlqHgjwd);
        ReturnResult returnResult = new ReturnResult();
        returnResult.setErrorCode("0");
        returnResult.setData("修改成功");
        return returnResult;
    }

    @RequestMapping("/selectForList")
    public Result<IPage<GkGd>> selectForList(GkGd zpgEipDlqHgjwd, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Result<IPage<GkGd>> result = new Result<IPage<GkGd>>();
        Page<GkGd> page = new Page<GkGd>(pageNo, pageSize);
        QueryWrapper<GkGd> queryWrapper = new QueryWrapper<GkGd>(zpgEipDlqHgjwd);
        IPage<GkGd> pageList = gkGdService.page(page, queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }
}

